package com.demo

import java.awt.Dimension
import javax.swing.{ListCellRenderer, JList, JLabel}
import scala.swing._
import scala.swing.event._
import scala.xml.Node

/** GUI Twitter Client
 *  This is a GUI Twitter Client written in Scala
 *  using the scala-swing library.
 *
 *  @author Jorge Ortiz
 *  @version 0.1
 */
object Client extends SimpleGUIApplication {
  val top = new MainFrame {
    title = "Skittish"
    
    // Prompts the user for login information until valid
    // credentials have been provided
    new LoginDialog

    val statuses = Twitter.friendsTimeline

    val list = new ListView(statuses) {
      override def renderer(elem: Node, index: Int, isSelected: Boolean, cellHasFocus: Boolean) =
        new BoxPanel(Orientation.Vertical) {
          val nameLabel = new Label((elem \\ "name").text)
          val statusText = new TextArea((elem \\ "text").text)
          statusText.lineWrap = true
          statusText.wordWrap = true
          statusText.rows = 3
          // println(statusText.peer.getPreferredSize)
          
          contents.append(nameLabel, statusText)
        }
      
      peer.setFixedCellWidth(200)
      //peer.setFixedCellHeight(70)
    }

    contents = new ScrollPane(list)
  }
}
